<!-- 回款详情-下面的table表格组件  -->
<template>
  <div class="returned-record">
    <h3>发票记录</h3>
    <TableTurn
      :table-data="getData"
      ref="tableRef"
      :args="args"
      :is-show-pagination="false"
    >
      <a-table-column :width="80" align="center">
        <template #title> 序号 </template>
        <template #cell="{ rowIndex }">
          {{ rowIndex + 1 }}
        </template>
      </a-table-column>
      <a-table-column
        title="回款类型"
        :width="150"
        dataIndex="collectionTypeName"
        align="center"
      ></a-table-column>
      <a-table-column
        title="发票编号"
        :width="150"
        dataIndex="invoiceNumber"
        align="center"
      ></a-table-column>
      <a-table-column
        title="发票类型"
        :width="150"
        dataIndex="invoiceTypeName"
        align="center"
      ></a-table-column>
      <a-table-column
        title="发票税率"
        :width="150"
        dataIndex="invoiceTypeRate"
        align="center"
      ></a-table-column>
      <a-table-column
        title="开票科目"
        :width="150"
        dataIndex="invoicingSubject"
        align="center"
      ></a-table-column>
      <a-table-column
        title="开票金额"
        :width="150"
        dataIndex="invoicingPrice"
        align="center"
        ><template #cell="{ record }">${{ record.invoicingPrice }}</template>
      </a-table-column>
      <a-table-column
        title="开票人"
        :width="150"
        dataIndex="invoicingUserName"
        align="center"
      ></a-table-column>
      <a-table-column
        title="开票时间"
        :width="150"
        dataIndex="invoicingTime"
        align="center"
        ><template #cell="{ record }">{{
          dayjs(record.invoicingTime).format('YYYY-MM-DD')
        }}</template></a-table-column
      >
      <a-table-column
        title="发票凭证"
        :width="150"
        dataIndex="voucher"
        align="center"
      >
        <template #cell="{ record }">
          <a-button type="text" @click="viewVoucher(record)"></a-button>
        </template>
      </a-table-column>
    </TableTurn>
  </div>
</template>

<script lang="ts" setup>
  import { reactive, ref, computed, watch, onMounted, inject } from 'vue';
  import dayjs from 'dayjs';
  import * as apiList from '@/api/order-management/returned-management/base-setting';
  import { cloneDeep } from 'lodash';
  import router from '@/router';

  // 表格配置
  const args = reactive({
    stripe: true,
    scroll: {
      y: 500,
    },
    bordered: {
      headerCell: true,
    },
  });
  const refresh: any = inject('reload');
  const tableRef = ref();
  const isInvoiceVisible = ref(false);
  const clientId = ref();
  const props = withDefaults(
    //参数说明
    defineProps<{
      titleData: any;
      // clientId: number;
    }>(),
    {
      titleData: [],
    }
  );
  const invoiceId = ref();
  const getInvoiceData = ref();
  const tableData = ref(cloneDeep(props.titleData));

  // 获取表格数据
  const getData = async (page: any) => {
    try {
      const res = tableData.value;
      return Promise.resolve(res);
      // const res = await apiList.getCollectionInfo({ id });
    } catch (err: unknown) {
      console.log(err);
    }
  };

  // watch(
  //   () => props.orderId,
  //   (val) => {
  //     if (!val)
  //   }
  // );

  // 查看凭证
  const viewVoucher = (record: any) => {};

  // 编辑按钮
  const goEdit = (record: any) => {
    isInvoiceVisible.value = true;
    invoiceId.value = record.id;
    getInvoiceData.value = record;
  };

  const editinvoiceInfo = async (formdata: any) => {
    await apiList.putInvoiceInfo({ ...formdata });
    tableRef.value.loadData();
  };

  onMounted(() => {
    clientId.value = cloneDeep(props.clientId);
  });

  // 删除一项
  const deleteItem = async (id: number, rowIndex: number) => {
    const res = await apiList.delInvoiceInfo({ id });
    if (res === 'ok') {
      tableData.value.splice(rowIndex, 1);
      tableRef.value.loadData();
    }
    // router.go(0);
    // refresh();
  };
</script>

<style scoped lang="less"></style>
